

#include "main.h"
Bit16_ut output1;
u8       gb_wcoolon;
/********************************** */
void coolwindwork_deal(void)
{
    static u16 boxworktime = 0;
    if(bakeCtrl.state == STA_WORK)
    {
        if(system_sec_f)
            u16_up(&boxworktime);
    }
    else
    {
        if((bakeCtrl.state != STA_PAUSE)&&(bakeCtrl.state != STA_WORK))
        {
            boxworktime = 0;
        }            
    }    
    if(smoker.level)
    {
        if(gb_wcoolon == 0)
        {
            if(boxworktime >= 40*60)//40*60
            {
                gb_wcoolon = 1;
            }
        }
    }
    else
    {
        gb_wcoolon = 0;
    }
}
void clear_all_output(void)
{
	smoker.level	= 0;		   //关风机
	light_f 		= 0;
	atmos_f 		= 0;
	boxLight_f 		= 0;
	smokerpower_f   = 0;
    boxlock_f       = 0;
	cycle_f         = 0;
	cold_f          = 0;
	cut_stove_f     = 0;
    top_keepwarm_f  = 0;
    klight_f        = 0;
	klock           = 0;
    wash_f          = 0;
    
	board.cmd 		= 0;			   //关翻版

    gu8_AddWaterTime1 = 0;
    gu8_AddWaterTime2 = 0;
    gb_DryFireFlag = 0;
    steamPara.menu = WORK_ALLOFF;
    steamCtrl.state = STA_NULL; //关蒸箱
    bakePara.menu = BWORK_ALLOFF;
    bakeCtrl.state = STA_NULL; //关蒸箱     
    gb_TestFlag = 0;    
}


void update_all_output(void)
{

    static bool rfalg = 0;
    static bool lfalg = 0;
    if(gb_TestFlag)
        return;

    if(shell_leak_err)//破皮
    {
        EN15TOGND_OUTPIN = 1; //关闭点火器电源
    }
    else
    {
        EN15TOGND_OUTPIN = cut_stove_f;
    }
    GPIO_WriteBit(EN15_OUTPIN, 1);
    if(gb_wcoolon)
        GPIO_WriteBit(PREATMOS_OUTPIN, 1);
    else
        GPIO_WriteBit(PREATMOS_OUTPIN,0);
    // if(gb_outfireoff || boli.lowfire_f)
    //     GPIO_WriteBit(KPRE12V_OUTPIN, 0);
    // else
    //     GPIO_WriteBit(KPRE12V_OUTPIN, 1);
    if(gu8_draintime &&(steamCtrl.state != STA_PAUSE))
        GPIO_WriteBit(KPRE12V_OUTPIN, 1);
    else
        GPIO_WriteBit(KPRE12V_OUTPIN, 0);
    GPIO_WriteBit(LOCKK_OUTPIN, klock);   
    GPIO_WriteBit(LOCKZ_OUTPIN, boxlock_f);

    GPIO_WriteBit(ZBOX_LIGHT_OUTPIN, boxLight_f);//箱体灯
    KBOX_LIGHT_OUTPIN = klight_f;

    if(steamCtrl.state == STA_WORK) 
        GPIO_WriteBit(ADDWZ_OUTPIN, (gu8_AddWaterTime1 || gu8_AddWaterTime2) ? 1 : 0);    
    else
        GPIO_WriteBit(ADDWZ_OUTPIN, 0); 
      
   
    CYCLE_OUTPIN = cycle_f;//循环
    COLD_OUTPIN = cold_f; //冷却
    KEEPWARM_OUTPIN = top_keepwarm_f;
    WASH_OUTPIN = wash_f;

        

    /**********总开继电器****************/

    /***********熄火控制****************/
    /*
    * 考虑两边熄火电容是否完全独立，互不影响
    * 熄火电容电量是否只与熄火输出有关，会不会出现满电量不输出电量掉落的情况
    */
    if(gans_L.error && sta_Lfire)
        fireoff_L.cmd_flag = 1;
    if (system_100ms_f)
    {
        //L
        if(lfalg == 0)
        {
            u8_up(&fireoff_L.off_time);//150 == 15s
            fireoff_L.work_time = 0;
        }
        else 
        {
            u8_up(&fireoff_L.work_time);
            fireoff_L.off_time = 0;
        }
        //R
        if(rfalg == 0)
        {
            u8_up(&fireoff_R.off_time);
            fireoff_R.work_time = 0;
        }
        else
        {
            u8_up(&fireoff_R.work_time);
            fireoff_R.off_time = 0;
        }

    }
    if(fireoff_L.cmd_flag)
    {
        if(lfalg == 0)
        {
            if(fireoff_L.off_time <150)
            {
                lfalg = 0;
                GPIO_WriteBit(FIREOFF_L_OUTPIN, 1);                
            }
            else
            {
                lfalg = 1;
                GPIO_WriteBit(FIREOFF_L_OUTPIN, 0); 
            }
        }
        else
        {
            if(fireoff_L.work_time < 10)//熄火动作执行1S
            {
                lfalg = 1;
                GPIO_WriteBit(FIREOFF_L_OUTPIN, 0);                 
            }
            else
            {
                lfalg = 0;
                GPIO_WriteBit(FIREOFF_L_OUTPIN, 1);                   
            }
        }
    }
    else
    {
        if(lfalg)
        {
            lfalg = 0;
            fireoff_L.work_time = 0;
        }
        GPIO_WriteBit(FIREOFF_L_OUTPIN, 1);        
    } 
    if (fireoff_R.cmd_flag)
    {
        if(rfalg == 0)
        {
            if(fireoff_R.off_time <150)
            {
                rfalg = 0;
                GPIO_WriteBit(FIREOFF_R_OUTPIN, 1);                
            }
            else
            {
                rfalg = 1;
                GPIO_WriteBit(FIREOFF_R_OUTPIN, 0); 
            }
        }
        else
        {
            if(fireoff_R.work_time < 10)
            {
                rfalg = 1;
                GPIO_WriteBit(FIREOFF_R_OUTPIN, 0);                 
            }
            else
            {
                rfalg = 0;
                GPIO_WriteBit(FIREOFF_R_OUTPIN, 1);                   
            }
        }
    }
    else
    {
        if(rfalg)
            fireoff_R.work_time = 0;
        rfalg = 0;
        GPIO_WriteBit(FIREOFF_R_OUTPIN, 1);       
    }    
    /*******************************/
}
/*---------------------------------------------------------------------------*/
/* Name     :   tubeheat_out
 * Input    :
 * Output   :
 * Description: 输出使能
 *---------------------------------------------------------------------------*/
void tubeheat_out(void)
{
    static u8 t600ms_ct = 0;
    t600ms_ct++;
    if(t600ms_ct== 60)
    {
        t600ms_ct = 0;
        gb_heattubedeal = 1;
    }    
    bomi_heater_power_ctr();
    top_heater_power_ctr();
    outtop_heater_power_ctr();
    left_heater_power_ctr();
    bomo_heater_power_ctr();  
    //pre_heater_power_ctr(); 
    gb_heattubedeal = 0;     
}
/*---------------------------------------------------------------------------*/
/* Name     :   out_drive
 * Input    :
 * Output   :
 * Description: 输出使能
 *---------------------------------------------------------------------------*/
void out_drive(void)
{
    u8 i;

    if (!system_50ms_f) return;

    //CYCLE_OUTPIN = 1;
	// WASH_OUTPIN = 1;
	// KBOX_LIGHT_OUTPIN = 1;
	// PIN_HT_BOMI = 1;
    //KEEPWARM_OUTPIN = 1;
    //EN15TOGND_OUTPIN = 1;
    //COLD_OUTPIN = 1;
    //PIN_HT_TOP = 1;
    //PIN_HT_OTOP = 1;
    // PIN_HT_BOMI = 1;
    // PIN_HT_BOMO = 1;
    //PIN_HT_LEFT = 1;
    //PIN_HT_PRE = 1;
    reset_mx2012();

    for (i = 0; i < 11; i++)
    {
        data_mx2012((output1.reg_int >> i) & 0x0001);
    }
    data_b12_mx2012(PIN_HT_BOMI);

    en_mx2012();
}
